const os = require('os')
let interfaces = os.networkInterfaces()
const hostIp = function () {
  var IPv4
  if (process.platform === 'darwin') {
    for (let i = 0; i < interfaces.en0.length; i++) {
      if (interfaces.en0[i].family == 'IPv4') {
        IPv4 = interfaces.en0[i].address
      }
    }
  } else if (process.platform === 'win32') {
    for (let devName in interfaces) {
      let iface = interfaces[devName]
      // console.log(iface)
      for (let i = 0; i < iface.length; i++) {
        let alias = iface[i]
        if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
          IPv4 = alias.address
        }
      }
    }
  }

  return IPv4
}
console.log(hostIp().substr(0, 10))
module.exports = hostIp()
